<?php
require_once 'Mobitv/Admin/Action.php';

class TransactionAction extends Mobitv_Admin_Action
{
    public function execute()
    {
        $this->getDuration($duration, $fromDate, $toDate);

        $adminDao = Vega_Dao::factory('Mobitv_Admin_Admin');
        $data = $adminDao->getTransactionList($fromDate, $toDate);

        $this->_view->assign('duration', $duration);
        $this->_view->assign('fromDate', $fromDate);
        $this->_view->assign('toDate', $toDate);
        $this->_view->assign('data', $data);
    }

    private function getDuration(&$duration, &$fromDate, &$toDate)
    {
        $fromDate = $toDate = date("Y-m-d");

        $duration = isset($_GET['d']) ? $_GET['d'] : date("d/m/Y");
        if($duration) {
            $d = explode("-", $duration);
            $fromDate = $d[0];
            $toDate = isset($d[1]) ? $d[1] : false;

            if($fromDate) {
                $x = explode("/", $fromDate);
                $dd = isset($x[0]) ? trim($x[0]) : 0;
                $mm = isset($x[1]) ? trim($x[1]) : 0;
                $yy = isset($x[2]) ? trim($x[2]) : 0;
                $fromDate = "$yy-$mm-$dd";
            }

            if($toDate) {
                $x = explode("/", $toDate);
                $dd = isset($x[0]) ? trim($x[0]) : 0;
                $mm = isset($x[1]) ? trim($x[1]) : 0;
                $yy = isset($x[2]) ? trim($x[2]) : 0;
                $toDate = "$yy-$mm-$dd";
            }
            else $toDate = $fromDate;
        }
    }
}